public class MaxLength {
    // 最长无重复子数组
    // https://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4?tpId=295&tqId=1008889&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D295
    public int maxLength (int[] arr) {
        // write code here
        int left = 0;
        int right = 0;
        int[] hash = new int[100001];
        int maxLength = 0;
        while (right < arr.length) {
            while (right < arr.length && ++hash[arr[right]] == 1) {
                right++;
            }
            maxLength = Math.max(maxLength, right-left);
            while (left < right && --hash[arr[left]] == 0) {
                left++;
            }
            left++;
            right++;
        }
        return maxLength;
    }
}
